package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.domain.db.BlackList;
import com.tanhua.domain.db.UserInfo;
import com.tanhua.dubbo.mapper.BlackListMapper;
import com.tanhua.dubbo.mapper.UserInfoMapper;

import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class BlackListApiImpl implements BlackListApi {

    @Autowired
    private BlackListMapper blackListMapper;

    @Autowired
    private UserInfoMapper userInfoMapper;


    /**
     * 删除黑名单用户
     * @param userId
     * @param blackUserId
     */
    public void delete(Long userId, Long blackUserId) {
        QueryWrapper<BlackList> qw=new QueryWrapper<>();
        qw.eq("user_id",userId);
        qw.eq("black_user_id",blackUserId);
        blackListMapper.delete(qw);

    }

    /**
     * 分页查询黑名单
     *userInfoMapper.selectPage()只能查询单表
     *所以需要在userInfoMapper定义新方法 拓展分页
     *在定义分页方法:
     *          分页参数:page对象
     *          条件:要求
     *          sql语句中并没有体现出分页的参:page,pagesize
     *          mybatis-plus只需要一个配置类,自动对指定的查询(方法中传入了page对象)进行SQL的分页处理
     *              1.查询总数
     *              2.拼接limit条件 limit 1,5
     * @return
     */
    @Override
    public IPage<UserInfo> findPage(Integer page, Integer pagesize, Long userId) {
        Page<UserInfo> pages=new Page<>(page,pagesize);

        return userInfoMapper.findBlackList(pages, userId);

    }
}
